{% extends 'layout.html' %}
{% load static %}
{% block content %}
    <div class="container">
        <div class="panel panel-default">
            <div class="panel-heading">图一</div>
            <div class="panel-body">
                <div id="m0" style="width: 100%; height: 300px;"></div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="panel panel-default">
                    <div class="panel-heading">温湿度/PM图</div>
                    <div class="panel-body">
                        <div id="m1" style="width: 100%; height: 250px;"></div>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="panel panel-default">
                    <div class="panel-heading">图三</div>
                    <div class="panel-body">
                        <div id="m2" style="width: 100%; height: 300px;"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>

{% endblock %}

{% block js %}
    <script src="{% static 'js/echarts.js' %}"></script>
    <script type="text/javascript">

        $(function () {
            setInterval("initLine01()", 5000)
            setInterval("initLine02()", 5000)
            setInterval("initLine03()", 5000)
        })

        /**
         * 初始化折线图
         */
        function initLine01() {
            var chartDom = document.getElementById('m0');
            var myChart = echarts.init(chartDom);
            var option;

            option = {
                title: {
                    text: '物联网数据采集折线图1',
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: []
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                toolbox: {
                    feature: {
                        saveAsImage: {}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: []
                },
                yAxis: {
                    type: 'value'
                },
                series: []
            };
            $.ajax({
                url: "/iot/chart1/",
                type: "get",
                dataType: "JSON",
                success: function (res) {
                    if (res.status) {
                        option.legend.data = res.data.legend_list;
                        option.xAxis.data = res.data.xAxis_list;
                        option.series = res.data.series_list;
                        option && myChart.setOption(option);
                    }
                }
            })
        }

        function initLine02() {
            var chartDom = document.getElementById('m1');
            var myChart = echarts.init(chartDom);
            var option;

            option = {
                title: {
                    text: '数据采集折线图2',
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: []
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                toolbox: {
                    feature: {
                        saveAsImage: {}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: []
                },
                yAxis: {
                    type: 'value'
                },
                series: []
            };
            $.ajax({
                url: "/iot/chart2/",
                type: "get",
                dataType: "JSON",
                success: function (res) {
                    if (res.status) {
                        option.legend.data = res.data.legend_list;
                        option.xAxis.data = res.data.xAxis_list;
                        option.series = res.data.series_list;
                        option && myChart.setOption(option);
                    }
                }
            })
        }

        function initLine03() {
            var chartDom = document.getElementById('m2');
            var myChart = echarts.init(chartDom);
            var option;

            option = {
                 title: {
                    text: '氧化物图',
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: []
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                toolbox: {
                    feature: {
                        saveAsImage: {}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: []
                },
                yAxis: {
                    type: 'value'
                },
                series: []
            };

             $.ajax({
                url: "/iot/chart3/",
                type: "get",
                dataType: "JSON",
                success: function (res) {
                    if (res.status) {
                        option.legend.data = res.data.legend_list;
                        option.xAxis.data = res.data.xAxis_list;
                        option.series = res.data.series_list;
                        option && myChart.setOption(option);
                    }
                }
            })

        }
    </script>
{% endblock %}